package com.augurit.gzcgwsp.csshlj.web;

import java.io.IOException;
import java.util.List;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.augurit.gzcgwsp.csshlj.service.ICsshljclcService;
import com.augurit.gzcgwsp.csshlj.web.form.CsshljclcForm;
import com.augurit.wf.common.web.WfBusClientExtAction;


/**
 * 生活垃圾处理厂
 * @author Administrator
 *
 */
@SuppressWarnings( { "serial", "unchecked" })
@Results( {
	@Result(name ="toList", location = "/gzcgwsp/shljcz/listshljClc.jsp"),
	@Result(name ="toSave", location = "/gzcgwsp/shljcz/csshclc.jsp"),
	@Result(name ="toUpdate", location = "/gzcgwsp/shljcz/updatecsshclc.jsp"),
	
})
public class CsshljclcAction extends WfBusClientExtAction{
	@Autowired
	private ICsshljclcService csshljclcService;
	
	private CsshljclcForm form;
	
	private Long clcId;//主键id
	
	@Override
	public String wfBusSave() throws Exception {
	
		return null;
	}

	/**
	 * 到列表页面
	 * @return
	 */
	public String toList(){
		String czId=getRequest().getParameter("czid");
		if(StringUtils.isNotBlank(czId)){
			List<CsshljclcForm> list=csshljclcService.getListByCzId(Long.valueOf(czId));
			getRequest().setAttribute("list", list);
			getRequest().setAttribute("czid", czId);
		}
		return "toList";
	}
	
	public String toSave(){
		String czId=getRequest().getParameter("czid");
		getRequest().setAttribute("czid", czId);
		return "toSave";
	}
	
	/**
	 * 到修改页面结果
	 * @return
	 * @throws IOException 
	 */
	public String loadUpdate() throws IOException{
		if(clcId!=null){
			  form=this.csshljclcService.getForm(clcId);
			  JSONObject jsonObject = JSONObject.fromObject(form); 
		      String json=jsonObject.toString();
		      getResponse().getWriter().print(json);  
		}
		return null;
	}

	/**
	 * 到修改页面
	 * @return
	 * @throws IOException 
	 */
	public String toUpdate() throws IOException{
		String czid=getRequest().getParameter("czid");
		if(StringUtils.isNotBlank(czid)){
			getRequest().setAttribute("czid", czid);
			getRequest().setAttribute("clcId", clcId);
	
		}
		return "toUpdate";
	}	
	
	public String doSave() throws IOException{
		String sign="success";
		try {
			this.csshljclcService.SaveOrUpdate(form);
		} catch (Exception e) {
			sign="false";
		}
		getResponse().getWriter().print(sign);
		return null;
	}
	
	
	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String list() throws Exception {
		
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		if(clcId!=null){
			form=this.csshljclcService.getForm(clcId);
		}else{
			form=new CsshljclcForm();
		}
	}

	@Override
	public String save() throws Exception {
		return null;
	}

	public CsshljclcForm getModel() {
		return form;
	}

	public Long getClcId() {
		return clcId;
	}

	public void setClcId(Long clcId) {
		this.clcId = clcId;
	}

}
